// pages/mine/backstage/backstage.js 

const App = getApp()
let { AJAX, timeTranfer, imgUrl } = require("../../../utils/util.js")

Page({

   /**  
    * 页面的初始数据 
    */
   data: {
      navH: 0,
      info:'',
      level:null, 
      isBindCard:true,
      is_code:false,
     imgUrl: imgUrl
   },

   /** 
    * 生命周期函数--监听页面加载 
    */
   onLoad: function(options) {
      var vm = this
      this.setData({
         navH: App.globalData.navHeight
      })
      if (!wx.getStorageSync("ACCESSTOKEN")) {
         App.userInfoReadyCallback = res => {
            wx.setStorageSync('ACCESSTOKEN', res);
            vm.getIndexInfo()
            vm.getBank()
            vm.getMemberId()
         }
         return
      }
      vm.getIndexInfo()
      vm.getBank()
      vm.getMemberId()
   },

   /** 
    * 生命周期函数--监听页面初次渲染完成 
    */
   onReady: function() {

   },

   /** 
    * 生命周期函数--监听页面显示 
    */
   onShow: function() {

   },

   /** 
    * 生命周期函数--监听页面隐藏 
    */
   onHide: function() {

   },

   /** 
    * 生命周期函数--监听页面卸载 
    */
   onUnload: function() {

   },

   /** 
    * 页面相关事件处理函数--监听用户下拉动作 
    */
   onPullDownRefresh: function() {

   },

   /** 
    * 页面上拉触底事件的处理函数 
    */
   onReachBottom: function() {

   },

   /** 
    * 用户点击右上角分享 
    */
   onShareAppMessage: function() {

   },
   // 获取member
   getMemberId() {
      AJAX('member/member-info').then(res => {
      
         AJAX('qrcode/qrcode', 'POST', {
            url: 'pages/mine/grow/growrecord/growrecord',
            scene: res.data.member_id,
            type: "partner"
         }).then(res => {  
            this.setData({
               is_code:true
            })          
            wx.setStorageSync('firstCodeUrl', res.data.img)   
            wx.setStorageSync('is_code', this.data.is_code)                 
         })
      })

   },
   /** 
    * 返回按钮事件 
    * navBack 
    */
   navBack() {
      wx.switchTab({
         url: '/pages/mine/mine',
      })
   },
   infoBtn(){
      wx.navigateTo({
         url: '/pages/mine/shaer/shaer',
      })
   },
   /**
    * goInfo
    * 判断是否绑定银行卡
    */
   getBank() {
      AJAX("bank/get-bank").then(res => {       
         this.setData({
            isBindCard: res.have_data,
         })
      })
   },
   goInfo(){
     
      if (this.data.isBindCard==false){
         wx.navigateTo({
            url: '/pages/mine/bankCard/bindCard',
         })
      } else{
         wx.navigateTo({
            url: '/pages/mine/backstage/cashOut/cashOut',
         })
      }
   },
   /**
    * index
    * finance/index
    */
    getIndexInfo(){
       AJAX("finance/index").then(res => {
          console.log(res)
         if(res.status=='succeed'){
             this.setData({
                info: res.data,
                level: res.data.level
             })
         }else{
            wx.showToast({
               title: '数据错误',
               icon:'none',
               duration:2000
            })
         }
       })
    }
})